<?PHP
  class PageCreatorPage extends Editor{
    function __construct($page){
      $this->page = $page;
    }
  
    public function display(){
      if(!$_POST['localalias']){
        $template = new Template();
        $template->load("site_new");
        $template->assign_var("URL",Settings::getInstance()->get("host").$this->page->alias.".html");
        $template->assign_var("ALIAS",$_POST['alias']);
        if(substr($_SESSION['dir'],0,1) == "/" && $_SESSION['dir'] != "/"){
          $template->assign_var("DIR",substr($_SESSION['dir'],1)."/");
        }
        else if($_SESSION['dir'] == '' || $_SESSION['dir'] == "/"){
          $template->assign_var("DIR","");
        }
        else{
          $template->assign_var("DIR",$_SESSION['dir']."/");
        }
        $template->assign_var("HOST",Settings::getInstance()->get("host"));
        $template->assign_var("ENDING",".html");
        $types = Page::getPagesTypes();
        if($types){
          foreach($types as $type){
            $index = $template->add_loop_item("TYPES");
            $template->assign_loop_var("TYPES",$index,"CLASS",$type->class);
            $template->assign_loop_var("TYPES",$index,"NAME",$type->name);
          }
        }
        $template->output();
      }
      else{
        if($_SESSION['dir']){
          $dir = $GLOBALS['db']->EscapeString($_SESSION['dir'])."/";
        }
        else{
          $dir = "";
        }
        if(substr($dir,0,1) == "/"){
          $dir = substr($dir,1);
        }
        $id = Page::create($dir.$GLOBALS['db']->EscapeString($_POST['localalias']),$GLOBALS['db']->EscapeString($_POST['type']),$_POST['title']);
        if($id){
          $template = new Template();
          $template->load("site_new_succeeded");
          $template->assign_var("URL",Settings::getInstance()->get("host")."admin/pageedit.html?site=".$dir.$_POST['localalias']);
          $template->output();
        }
        else{
          $template = new Template();
          $template->load("message");
          $template->assign_var("MESSAGE","Die Seite konnte leider nicht erstellt werden.");
          $template->output();
        }
      }
    }
    function getHeader(){
      $host = Settings::getInstance()->get("host");
      return "<script type=\"text/javascript\" src=\"".$host."system/plugins/jquery/jquery-1.4.2.js\"></script>";
   }
    
    public function getEditableCode(){
      return "<input name=\"save\" type=\"submit\" value=\"&Auml;ndern\" onclick=\"form.action='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."' ; target='_self' ; return true\" />";
    }
    
    public function save($newPage,$oldPage){
    }

    public function displayBreadcrumb($separator,$class,$idpraefix){
      FolderBreadcrumb::display($this->page,$separator,$class,$idpraefix);
    }  
}
?>